<!DOCTYPE html>
<html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>yunpos</title>
    <link href="images/img.jpg" rel="icon" type="image/x-icon" />
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    </head>
    <body>
        <div id="app">
            123
            <div class="loading">loading</div>
        </div>
        <script>
            $(function(){
            	var sum = 0;
            	var loading = $('.loading');
	            $.ajaxSetup({
		            url: 'https://jsonplaceholder.typicode.com/comments',
		            beforeSend: function () {
		            	sum++;
                        loading.show();
		            },
		            complete: function(){
		            	sum--;
                        if(sum == 0){
	                        loading.hide();
                        }
		            }
	            });
                $.ajax({
	                //url: 'https://jsonplaceholder.typicode.com/comments',
	                success:function (res) {
		               console.log(res)
	                }
                })

            })
        </script>
    </body>
</html>
